// arr1 = new Array();
// arr2 = [];
// console.log(typeof arr1); //无法判断是数组对象
// console.log(Array.isArray(arr1));

// arr = ["red", "green", "blue"];
// console.log(arr[0]);
// console.log(arr.length);
// //arr[99] = 1;
// //console.log(arr.length);
// for (let elm of arr) console.log(elm);
//
// console.log(arr.includes("red"));
// console.log(arr.indexOf("red"));
// console.log(arr.lastIndexOf("red"));
// arr.push("black");
// console.log(arr);
// console.log(arr.shift());
// console.log(arr);
// console.log(arr.pop());
// console.log(arr);
// arr.unshift("yellow");
// console.log(arr);
// arr.splice(1, 2, "white");
// console.log(arr);

// const subarr = arr.slice(1, 3);
// console.log(subarr);

// const one = ["one"],
//   two = ["two"];
// const concatArr = one.concat(two);
// console.log(concatArr);

// // arry -> string
// const joinstr = arr.join(":");
// console.log(joinstr);
// console.log(joinstr.split(":"));

const arr = [
  { name: "张三", age: 20 },
  { name: "李四", age: 22 },
  { name: "王五", age: 21 },
];
arr.forEach((item, index) => {
  console.log(`${index}: 姓名:${item.name}, 年龄:${item.age}`);
});
const firstFind = arr.find((elm) => {
  return elm.age > 20;
});
console.log(firstFind);

const findAll = arr.filter((elm) => elm.age > 20);
console.log(findAll);

arr.sort((a, b) => a.age - b.age);
console.log(arr);

console.log("age + 1:");
const arrMap = arr.map((item) => {
  return Object.assign({}, item, { age: item.age + 1 });
});
console.log(arrMap);
console.log(arr === arrMap);
